﻿using System;
using System.Dynamic;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;

namespace jsonar.test
{
	public partial class tt : System.Web.UI.Page
	{
		public jsonar.Obj json;
		public string str;
		public string html;

		protected void Page_Load(object sender, EventArgs e)
		{
			//test();
			var f = this.Request.Form["json"];
			if (string.IsNullOrWhiteSpace(f)) init();
			else form(f);
		}

		private void test()
		{
			var s0 = "2014/05/25 \r\ncc\t "; int num = 1;
			var arr = new Arr();
			arr.AddObj().Add("time", s0 + num++);

			var s = arr.ToString();
			arr = Json.Parse(s) as Arr;
			arr.AddObj().Add("time", s0 + num++);

			s = arr.ToString();
			arr = Json.Parse(s) as Arr;
			arr.AddObj().Add("time", s0 + num++);

			str = arr.ToString();
			html = arr.toHtml();
		}
		private void form(string s)
		{
			var j = Json.Parse(s);
			if (j == null) return;
			str = s;
			html = j.toHtml();
		}
		private void init()
		{
			json = new jsonar.Obj();
			t1();
			t2();
			t3();
			t11();
			dynamic d = new ExpandoObject();
			d.a = 3;
			d.up = "upme";
			json.Add("var", d);
			json.Add("http.Form", jsonar.Json.Parse(this.Request.Form["json"]));
			json.Add("http.Headers", this.Request.Headers, 5);
			json.Add("http.Params", this.Request.Params, 5);
			str = json.ToString();
			html = json.toHtml();
		}

		private void t1()
		{
			int[] coll = new int[10];
			for (int i = 0; i < 10; i++)
			{
				coll[i] = i;
			}
			json.Add("sys.Arr", jsonar.Json.GetJson(coll));
		}
		private void t2()
		{
			Dictionary<string, int> coll = new Dictionary<string, int>();
			for (int i = 0; i < 10; i++)
			{
				coll.Add(i.ToString(), i);
			}
			json.Add("sys.Dict", jsonar.Json.GetJson(coll));
		}
		private void t3()
		{
			Hashtable coll = new Hashtable();
			for (int i = 0; i < 10; i++)
			{
				coll.Add(i, i);
			}
			json.Add("sys.Hash", jsonar.Json.GetJson(coll));
		}
		private void t11()
		{
			json.AddArr("dynamic", 100).Add(new[]{
			new {name = "Login", descr = "登录", table = "", apis = new[] { 
				new { name= "Pwd", parames= "mobile,pwd", auth=false, descr="自动登录（密码）" },
				new{ name= "Code", parames= "mobile,code", auth=false, descr= "验证登录（短信）" },
				new{ name= "SendCode", parames= "mobile", auth=false, descr= "发送短信验证码" },
				new{ name= "CheckToken", parames= "user,token", auth=false, descr= "检查令牌有效" },
				new{ name= "Debug", parames= "mobile", auth=false, descr= "获取用户登录信息，调试登录而不用实际发送短信" }}},

			new { name = "Profession", descr = "tbs.DictProfession.Table.Alias", table = "doc.CombineTableLink(tbs.DictProfession.Table)", apis = new[] { 
				new { name = "GetAll", parames="", auth=false, descr="" },
				new { name = "GetAllArr", parames="", auth=false, descr="" }}},
			new { name = "StarSign", descr = "tbs.DictStarSign.Table.Alias", table = "doc.CombineTableLink(tbs.DictStarSign.Table)", apis = new[] {  
				new { name = "GetAll", parames="", auth=false, descr="" },
				new { name = "GetAllArr", parames="", auth=false, descr="" }}}, 
			new { name = "Sex", descr = "性别", table = "doc.CombineTableLink(tbs.DictSex.Table)", apis = new[] { 
				new { name = "GetAll", parames="", auth=false, descr="" },
				new { name = "GetAllArr", parames="", auth=false, descr="" }}}, 
			new { name = "ServiceMethod", descr = "tbs.DictServiceMethod.Table.Alias", table = "doc.CombineTableLink(tbs.DictServiceMethod.Table)", apis = new[] {  
				new { name = "GetAll", parames="", auth=false, descr="" },
				new { name = "GetAllArr", parames="", auth=false, descr="" }}}, 
			new { name = "FeeType", descr = "tbs.DictFeeType.Table.Alias", table = "doc.CombineTableLink(tbs.DictFeeType.Table)", apis = new[] { new { name = "GetAll", parames="", auth=false, descr="" }}},
			new {name = "RedPaper", descr = "tbs.RedPaper.Table.Alias", table = "doc.CombineTableLink(tbs.RedPaper.Table)", apis = new[] { 
				new { name= "Get", parames= "@id", auth=false, descr="获取红包数据" },
				new { name= "Gets", parames= "@ids", auth=false, descr="获取多个红包数据" },
				new { name= "GetsArr", parames= "@ids", auth=false, descr="获取多个红包数据" }}},

			new {name = "UserBind", descr = "tbs.UserBind.Table.Alias", table = "doc.CombineTableLink(tbs.UserBind.Table)", apis = new[] { 
				new { name= "GetAll", parames= "user", auth=false, descr="获取用户的绑定帐号数据" },
				new { name= "GetAllArr", parames= "user", auth=false, descr="获取用户的绑定帐号数据" },
				new { name= "GetMyAll", parames= "", auth=true, descr="获取自己的绑定帐号数据" },
				new { name= "GetMyAllArr", parames= "", auth=true, descr="获取自己的绑定帐号数据" },
				new{ name= "Ins", parames= "Conv.Join<string>(new[]{tbs.UserBind.Type.Name, tbs.UserBind.Account.Name, tbs.UserBind.AccountName.Name, tbs.UserBind.AccountInfo.Name})", auth=true, descr= "新增绑定帐号" },
				new{ name= "Del", parames= "@id", auth=true, descr= "删除绑定帐号" }}},
			new {name = "UserFavorite", descr = "tbs.UserFavorite.Table.Alias", table = "doc.CombineTableLink(tbs.UserFavorite.Table)", apis = new[] { 
				new { name= "GetAll", parames= "", auth=true, descr="获取用户自己的收藏" },
				new { name= "GetAllArr", parames= "", auth=true, descr="获取用户自己的收藏" },
				new{ name= "Ins", parames= "tbs.UserFavorite.Service.Name", auth=true, descr= "新增收藏" },
				new{ name= "Del", parames= "@id", auth=true, descr= "删除收藏" }}},
			new {name = "UserStat", descr = "tbs.UserStat.Table.Alias", table = "doc.CombineTableLink(tbs.UserStat.Table)", apis = new[] { 
				new { name= "Get", parames= "", auth=true, descr="获取用户统计和状态" }}},

			new {name = "Service", descr = "tbs.Service.Table.Alias", table = "doc.CombineTableLink(tbs.Service.Table)", apis = new[] { 
				new { name= "Get", parames= "@id", auth=false, descr="获取服务数据" },
				new { name= "Gets", parames= "@ids", auth=false, descr="获取多个服务数据" },
				new { name= "GetsArr", parames= "@ids", auth=false, descr="获取多个服务数据" },
				new { name= "GetRefer", parames= "@id", auth=false, descr="获取服务和相关数据" },
				new { name= "GetReferArr", parames= "@id", auth=false, descr="获取服务和相关数据" },
				new { name= "GetMyRefer", parames= "", auth=true, descr="获取我的服务和相关数据" },
				new { name= "GetMyReferArr", parames= "", auth=true, descr="获取我的服务和相关数据" },
				new { name= "GetRefers", parames= "@ids", auth=false, descr="获取多个服务和相关数据" },
				new { name= "GetRefersArr", parames= "@ids", auth=false, descr="获取多个服务和相关数据" },
				new { name= "Find", parames= "area,catagory,\nminLatitude,maxLatitude,minLongtitude,maxLongtitude", auth=false, descr="按范围搜索服务，area必需；catagory一级类目；minLatitude,maxLatitude,minLongtitude,maxLongtitude地理范围，4个参数同时有值时才有效" },
				new { name= "FindArr", parames= "", auth=false, descr="同Find，输出数组格式" },
				new { name= "Search", parames= "area,key", auth=false, descr="按关键字搜索服务，area必需；key关键字，匹配服务名称或开店人名称" },
				new { name= "SearchArr", parames= "", auth=false, descr="同Search，输出数组格式" },
				new{ name= "Ins", parames= "表字段", auth=true, descr= "开通服务，ID就是User的ID" },
				new{ name= "Upd", parames= "表字段", auth=true, descr= "修改服务，ID就是User的ID" }}},
			new {name = "ServiceDate", descr = "tbs.ServiceDate.Table.Alias", table = "doc.CombineTableLink(tbs.ServiceDate.Table)", apis = new[] { 
				new { name= "Get", parames= "@id", auth=false, descr="" },
				new{ name= "Upd", parames= "表字段", auth=true, descr= "修改或新建服务可预约时间，ID就是Service的ID" }}},
			new {name = "ServiceBill", descr = "tbs.ServiceBill.Table.Alias", table = "doc.CombineTableLink(tbs.ServiceBill.Table)", apis = new[] { 
				new { name= "GetAll", parames= "", auth=true, descr="获取服务的收支账单" },
				new { name= "GetAllArr", parames= "", auth=true, descr="获取服务的收支账单" }}},
			new {name = "Order", descr = "tbs.Order.Table.Alias", table = "doc.CombineTableLink(tbs.Order.Table)", apis = new[] { 
				new { name= "Get", parames= "@id", auth=true, descr="获取指定的订单" },
				new { name= "GetAll", parames= "service", auth=true, descr="service=1时获取服务的全部订单，否则获取用户全部的" },
				new { name= "GetAllArr", parames= "service", auth=true, descr="service=1时获取服务的全部订单，否则获取用户全部的" }}},
		}, 5, true);
		}
	}
}